<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitUpdate79 extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::dropIfExists('activities');
        Schema::dropIfExists('activity_egg_lottery');
        Schema::dropIfExists('activity_invite_records');
        Schema::dropIfExists('activity_lottery');
        Schema::dropIfExists('activity_lottery_ticket');
        Schema::dropIfExists('activity_records');
        Schema::dropIfExists('activity_seckill');
        Schema::dropIfExists('activity_skus');
        Schema::dropIfExists('activity_yifanshang');
        
        Schema::table('rotate_lottery', function (Blueprint $table) {

            $table->boolean('is_invite_enabled')->default(0)->index()->comment('是否开启邀请机制');
            $table->json('invite_rule')->nullable()->comment('邀请规则');

            $table->integer('invite_user_total')->default(0)->index()->comment('拉新用户数');
            $table->integer('join_user_total')->default(0)->index()->comment('参与用户数');
            
        });

        Schema::table('users', function (Blueprint $table) {

            $table->char('invite_node_type', 30)->nullable()->index()->comment('邀请节点类型');
            $table->uuid('invite_node_uuid')->nullable()->index()->comment('邀请节点类型uuid');
            $table->integer('invite_node_id')->nullable()->index()->comment('邀请节点类型id');
            
        });

        Schema::table('invite_records', function (Blueprint $table) {

            $table->char('invite_node_type', 30)->nullable()->index()->comment('邀请节点类型');
            $table->uuid('invite_node_uuid')->nullable()->index()->comment('邀请节点类型uuid');
            $table->integer('invite_node_id')->nullable()->index()->comment('邀请节点类型id');
            $table->string('invite_node_title', 255)->nullable()->comment('邀请节点类型标题');
            
        });

        Schema::table('activity_tickets', function (Blueprint $table) {

            $table->integer('stock')->default(0)->index()->comment('当前剩余');

            $table->integer('reward_total')->default(0)->index()->comment('系统赠送的次数');
            $table->integer('buy_total')->default(0)->index()->comment('购买的次数');
            $table->integer('used_total')->default(0)->index()->comment('已使用次数');

        });

        Schema::table('activity_ticket_records', function (Blueprint $table) {

            $table->tinyInteger('sub_type')->nullable()->index()->comment('1为邀请基本奖励  2为邀请额外奖励 3为签到奖励');
            
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
    }
}
